//
//  JKJRecommendViewController.m
//  jiukeji
//
//  Created by 小宇 on 2017/11/23.
//  Copyright © 2017年 小宇. All rights reserved.
//

#import "JKJRecommendViewController.h"
#import "SDCycleScrollView.h"
#import "Masonry.h"
#import "JKJShopInfoTabView.h"
#import "JKJShopInfoTabViewCell.h"
#import "SpeedloanViewController.h"
#import "JKJSpeedloanModel.h"
#import "JKJloanRecommendViewController.h"
#import "JKJRecommendModel.h"
#import "JKJLUBOTUModel.h"
@interface JKJRecommendViewController ()<SDCycleScrollViewDelegate>
@property (nonatomic,strong) NSArray *modelArray;//首页模型数组
// 轮播图图片数组
@property (nonatomic, strong)NSMutableArray * imagesArray;

@property (nonatomic, strong)NSThread * myImageArrayThread;
@end

@implementation JKJRecommendViewController

-(NSMutableArray *)imagesArray{
	if(!_imagesArray){
		_imagesArray = [[NSMutableArray alloc] init];
	}
	return _imagesArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	self.view.backgroundColor = [UIColor whiteColor];
	UIView *topView = [[UIView alloc] init];
	topView.frame = CGRectMake(0, 0, self.view.frame.size.width, 280);
	topView.backgroundColor = [UIColor hm_colorWithHex:0xf8f8f8];

	[self.view addSubview:topView];


//
//	UIScrollView *scrollView = [[UIScrollView alloc] init];
//	[self.view addSubview:scrollView];
//	scrollView.backgroundColor = [UIColor hm_colorWithHex:0xf8f8f8];
//	[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//		make.edges.equalTo(self.view);
//	}];
	//轮播图
	UIImage *image = [UIImage imageNamed:@"banner"];
	SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:image];

//	NSArray *array = @[@"banner",@"banner",@"banner",@"banner"];
//	SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageNamesGroup:array];
	[topView addSubview:cycleScrollView];
	[cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.height.equalTo(@(175 * SCREEN_RATE));
		make.top.equalTo(topView);
		make.left.right.equalTo(topView);
	}];
//
	self.automaticallyAdjustsScrollViewInsets = NO;


	UIView *titleView = [[UIView alloc] init];
	[topView addSubview:titleView];
	titleView.backgroundColor = [UIColor whiteColor];
	[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(cycleScrollView.mas_bottom);
		make.left.right.equalTo(topView);
		make.height.equalTo(@(60 * SCREEN_RATE));
	}];

	float f = [UIScreen mainScreen].bounds.size.width;

	UIButton *button = [UIButton cz_textButton:@" 极速贷款" fontSize:14 normalColor:0 selectedColor:0];
	[titleView addSubview:button];

	[button addTarget:self action:@selector(Speedloan) forControlEvents:UIControlEventTouchUpInside];

	[button setImage:[UIImage imageNamed:@"logo底纹"] forState:UIControlStateNormal];
	//设置粗体
	[button setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
	[button mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(topView).offset(f * 0.15);
		make.centerY.equalTo(titleView);
	}];
////
//	//中间的线
	UIView *lineView1 = [[UIView alloc] init];
	[titleView addSubview:lineView1];
	lineView1.backgroundColor = [UIColor hm_colorWithHex:0xe6e6e6];
	[lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.center.equalTo(titleView);
		make.height.equalTo(@(40));
		make.width.equalTo(@(1));
	}];
//
	UIButton *button1 = [UIButton cz_textButton:@" 贷款推荐" fontSize:14 normalColor:0 selectedColor:0];

	[button1 addTarget:self action:@selector(loanRecommend) forControlEvents:UIControlEventTouchUpInside];
	//设置粗体
	[button1 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
	[titleView addSubview:button1];
	[button1 setImage:[UIImage imageNamed:@"logo底纹"] forState:UIControlStateNormal];

	[button1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(topView).offset(f * 0.65);
		make.centerY.equalTo(titleView);
	}];

	UILabel *titleLab = [UILabel cx_textLabel:@"热门贷款" fontSize:14 Color:0x333333];
	[topView addSubview:titleLab];
	[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(@(5));
		make.top.equalTo(titleView.mas_bottom).offset(15);
	}];

	[titleLab setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];


	
	JKJShopInfoTabView *shopInfoTabView = [[JKJShopInfoTabView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
	[self.view addSubview:shopInfoTabView];
	shopInfoTabView.tableHeaderView = topView;

	//去除分割线
	shopInfoTabView.separatorStyle = UITableViewCellSeparatorStyleNone;
	shopInfoTabView.rowHeight = 140 * SCREEN_RATE;
	[shopInfoTabView registerClass:[JKJShopInfoTabViewCell class] forCellReuseIdentifier:@"JKJShopInfoTabViewCell"];
	shopInfoTabView.backgroundColor = [UIColor hm_colorWithHex:0xf8f8f8];
	[shopInfoTabView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.bottom.equalTo(self.view).offset(-49);
		make.top.equalTo(self.view).offset(64);
		make.left.right.bottom.equalTo(self.view);
	}];


	[[CXNetworkTool sharedTool] getRequestWithURL:@"products" parameters:nil complete:^(id responseObject, NSError *error) {
		NSArray *modelArray = [NSArray yy_modelArrayWithClass:[JKJRecommendModel class] json:responseObject];
		_modelArray = modelArray;
		shopInfoTabView.modelArray = _modelArray;
		[shopInfoTabView reloadData];
	}];


	[[CXNetworkTool sharedTool] getRequestWithURL:@"slides" parameters:nil complete:^(id responseObject, NSError *error) {
		NSArray *lubotuArray = [NSArray yy_modelArrayWithClass:[JKJLUBOTUModel class] json:responseObject];
		for(int i = 0; i < lubotuArray.count; i++){
//			UIImageView * imageView = [[UIImageView alloc] init];
//			[imageView sd_setImageWithURL:[NSURL URLWithString:lubotuArray[i]]];
			JKJLUBOTUModel *model = lubotuArray[i];
			[self.imagesArray addObject:model.thumbnail];
		}
		cycleScrollView.imageURLStringsGroup = self.imagesArray;
	}];

	[[CXNetworkTool sharedTool] getRequestWithURL:@"users/me" parameters:nil complete:^(id responseObject, NSError *error) {

	}];
}
//
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
	NSLog(@"%d",index);
}

-(void)loanRecommend{
	JKJloanRecommendViewController *loan = [[JKJloanRecommendViewController alloc] init];
	[self.navigationController pushViewController:loan animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)Speedloan{
	SpeedloanViewController *speed = [[SpeedloanViewController alloc] init];
	[self.navigationController pushViewController:speed animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
